<?php

namespace Analysis\Model;

use Think\Model;

class TextchelModel extends Model
{
    protected $autoCheckFields = false;

    const ACCON = 'yuyibao';
    const PASWD = 'yubao_123';
    const URL = 'http://222.73.117.158/msg/HttpBatchSendSM?';

    private $phone;
    private $val;

    public function getSmsParam($mo, $val)
    {
        $this->phone = $mo;
        $this->val = $val;
        return $this->constData();
    }

    private function constData()
    {
        $temp = array(
            "account" => iconv('GB2312', 'GB2312', self::ACCON),
            "pswd" => iconv('GB2312', 'GB2312', self::PASWD),
            "mobile" => $this->phone,
            "msg" => mb_convert_encoding($this->val, 'UTF-8', 'auto')
        );
        $o = "";
        foreach ($temp as $k => $v) {
            $o.= "$k=" . urlencode($v) . "&";
        }
        $post_data = substr($o, 0, -1);
        return $this->toSend($post_data);
    }

    private function toSend($data)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, self::URL);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $return = curl_exec($ch);
        curl_close($ch);
        return $return;
    }
}
